package com.bianguo.android.apushdemo.view.activity;

import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bianguo.android.apushdemo.R;
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarView;

import butterknife.BindView;
import butterknife.OnClick;

public class CalendarActivity extends BaseActivity implements CalendarView.OnDateSelectedListener, CalendarView.OnDateChangeListener {

    @BindView(R.id.title_bar_layout)
    RelativeLayout titleLayout;
    @BindView(R.id.title_title)
    TextView titleTitle;
    @BindView(R.id.title_bar_right_tv)
    TextView titleRightTv;
    @BindView(R.id.calendar_calendarView)
    CalendarView calendarView;

    @Override
    public int layoutId() {
        return R.layout.activity_calendar;
    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        titleLayout.setBackgroundColor(ActivityCompat.getColor(mContext, R.color.colorMeTitleBar));
        titleTitle.setText("评标日期");
        titleRightTv.setVisibility(View.VISIBLE);
        titleRightTv.setText(calendarView.getCurYear() + "年" + calendarView.getCurMonth() + "月");
        calendarView.setWeeColor(ActivityCompat.getColor(mContext, R.color.colorMeTitleBar), ActivityCompat.getColor(mContext, R.color.white));
        calendarView.setSelectedColor(1, ActivityCompat.getColor(mContext, R.color.colorMeTitleBar), ActivityCompat.getColor(mContext, R.color.white));
        calendarView.setOnDateChangeListener(this);
        calendarView.setOnDateSelectedListener(this);
    }

    @Override
    public void setStatusColor(int color) {
        super.setStatusColor(ActivityCompat.getColor(mContext, R.color.colorMeTitleBar));
    }

    @OnClick({R.id.title_left_ib, R.id.title_bar_right_tv})
    public void onClickBk(View view) {
        switch (view.getId()) {
            case R.id.title_left_ib:
                onBackPressed();
                break;
            case R.id.title_bar_right_tv:
                calendarView.showSelectLayout(calendarView.getCurYear());
                titleRightTv.setText(calendarView.getCurYear() + "年");
                break;
        }
    }

    @Override
    public void onDateSelected(Calendar calendar) {
    }

    @Override
    public void onDateChange(Calendar calendar) {
        titleRightTv.setText(calendar.getYear() + "年" + calendar.getMonth() + "月");
    }

    @Override
    public void onYearChange(int year) {
        titleRightTv.setText(year + "年");
    }
}
